<?php
	header('Content-type: application/json');
	header('Access-Control: allow <*>');
	include("includes/connect.php");
	include("functions/mobile_registration_functions.php");
	
	$username = $_GET['username'];
	$ChkPt1 = ChkUserName($username);

	if($ChkPt1 == 1)
	{
		$email = $_GET['emailaddress'];
		$ChkPt2 = ChkEmail($email);

		if($ChkPt2 == 1)
		{
			$passworda = $_GET['password'];
			$passwordb = $_GET['confirmpassword'];
			$ChkPt3 = ChkPassword($passworda,$passwordb);

            if($ChkPt3 == 1)
            {
                $MD5Password = md5($passworda);

                if($ChkPt1 == 1 && $ChkPt2 == 1 && $ChkPt3 == 1)
                {
                    $InsertNewUser = "INSERT INTO `user_table` (`username`, `password`, `email`, `GID`) VALUES ('$username', '$MD5Password', '$email', '2')";
                    mysql_query($InsertNewUser) or die("could not register users or send email out");
					
					$resultMSG['message']="Registration succeeded.";
					$resultMSG['returnCode']=1;
					$resultMSG['username']= $_GET['username'];
					$resultMSG['password']= $_GET['password'];
					echo json_encode($resultMSG);

                }
                else
				{ 
					$resultMSG['message']="Registration failed. Please check your entries and try again.";
					$resultMSG['returnCode']=0;
					$resultMSG['username']= $_GET['username'];
					$resultMSG['password']= $_GET['password'];
					echo json_encode($resultMSG); 
				}
            }
            else
			{ 
				$resultMSG['message']="Password error. Make sure you typed your password the same way twice.";
				$resultMSG['returnCode']=0;
				$resultMSG['username']= $_GET['username'];
				$resultMSG['password']= $_GET['password'];
				echo json_encode($resultMSG); 
			}
        }
        else
		{
			$resultMSG['message']="Email error. This email may already be used.";
				$resultMSG['returnCode']=0;
				$resultMSG['username']= $_GET['username'];
				$resultMSG['password']= $_GET['password'];
				echo json_encode($resultMSG); 
		}
    }
    else
	{
		$resultMSG['message']="Username error. This name may already be taken.";
				$resultMSG['returnCode']=0;
				$resultMSG['username']= $_GET['username'];
				$resultMSG['password']= $_GET['password'];
				echo json_encode($resultMSG); 
	}
?>